package com.ruoyi.project.wms.logistics.chuhuo.order.service.impl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.wms.logistics.chuhuo.order.service.IChuWmsOrderService;
import com.ruoyi.project.wms.logistics.ordermanager.domain.WmsOrder;
import com.ruoyi.project.wms.logistics.ordermanager.mapper.WmsOrderMapper;
import com.ruoyi.project.wms.outgoods.domain.WmsOutGoods;
import com.ruoyi.project.wms.outgoods.mapper.WmsOutGoodsMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-09-30
 */
@Service
public class ChuWmsOrderServiceImpl implements IChuWmsOrderService
{
    @Resource
    private WmsOrderMapper wmsOrderMapper;
    @Resource
    private WmsOutGoodsMapper wmsOutGoodsMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param oid 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public WmsOrder selectWmsOrderById(Long oid)
    {
        return wmsOrderMapper.selectWmsOrderById(oid);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param wmsOrder 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<WmsOrder> selectWmsOrderList(WmsOrder wmsOrder)
    {
        wmsOrder.setOstatus("准备发货");
        return wmsOrderMapper.selectWmsOrderList(wmsOrder);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param wmsOrder 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertWmsOrder(WmsOrder wmsOrder)
    {
        return wmsOrderMapper.insertWmsOrder(wmsOrder);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param wmsOrder 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateWmsOrder(WmsOrder wmsOrder)
    {
        return wmsOrderMapper.updateWmsOrder(wmsOrder);
    }

    /**
     * 删除【请填写功能名称】对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWmsOrderByIds(String ids)
    {
        return wmsOrderMapper.deleteWmsOrderByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param oid 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteWmsOrderById(Long oid)
    {
        return wmsOrderMapper.deleteWmsOrderById(oid);
    }

    /**
     * 生成出货单
     * @param onum
     * @return
     */
    @Override
    public int createChuhuo(String onum) {
        //创建出货单对象
        WmsOutGoods wmsOutGoods = new WmsOutGoods();
        wmsOutGoods.setOgonum(onum);
        wmsOutGoods.setOgcreatedate(new Date());
        wmsOutGoods.setOgstatus("待出库");
        //从session中获取登录人
        Session session = SecurityUtils.getSubject().getSession();
        String username = (String) session.getAttribute("username");
        wmsOutGoods.setOgcreator(username);
        wmsOutGoods.setOgtransport("顺丰速运");
        //生成出货单
        int i = wmsOutGoodsMapper.insertWmsOutGoods(wmsOutGoods);
        //修改订单状态为挑拣
        String ostatus = "挑拣";
        wmsOrderMapper.updateWmsOrderByOnum(ostatus,onum);
        return i;
    }
}
